package com.example.carrierapp.ui.person.video;

import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.MediaController;
import android.widget.VideoView;

import com.example.carrierapp.base.BaseActivity;
import com.example.carrierapp.config.ConstValue;
import com.example.carrierapp.util.ToastUtils;
import com.example.lb.fingerdemo.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class FullscreenVideoActivity extends BaseActivity {

    @BindView(R.id.video_view)
    VideoView mVideoView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        String title=getIntent().getStringExtra(ConstValue.TITLE);
        setTitleString(title);
        String url=getIntent().getStringExtra(ConstValue.URL);
        if(TextUtils.isEmpty(url))
        {
            ToastUtils.showCenterToast(this,"地址无效");
           return;
        }

        ToastUtils.showCenterToast(this,"视频正在加载中，请稍后。。。");
        initVideo(url);

    }

    private void initVideo(String url) {
        Uri uri = Uri.parse(url);//将路径转换成uri
        mVideoView.setVideoURI(uri);//为视频播放器设置视频路径

        mVideoView.setMediaController(new MediaController(FullscreenVideoActivity.this));//显示控制栏
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mVideoView.start();//开始播放视频
            }
        });
        mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                mp.prepareAsync();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public int getContentView() {
        return R.layout.activity_video_fullscrren;
    }

    @Override
    public String getTitleString() {
        return "操作视频";
    }
}
